
#ifndef  COMPARATOR_CPP_H
#define  COMPARATOR_CPP_H


// 报单排序比较小于条件判断
static bool _compare_baodan_lt(void* data1, void* data2, int field) {
	SBAODAN* a = (SBAODAN*)data1;
	SBAODAN* b = (SBAODAN*)data2;
	switch (field) {
	case FIELD_BAODAN_NONE:
	default:
		return a->iO00 < b->iO00;
	case FIELD_BAODAN_iT12_part:
		return a->iT12_part < b->iT12_part || ((a->iT12_part == b->iT12_part) && (a->iO00 < b->iO00));
	case FIELD_BAODAN_cI10:
		return a->cI10 < b->cI10 || ((a->cI10 == b->cI10) && (a->iO00 < b->iO00));
	case FIELD_BAODAN_iM30:
		return a->iM30 < b->iM30 || ((a->iM30 == b->iM30) && (a->iO00 < b->iO00));
	case FIELD_BAODAN_iO06:
		return a->iO06 < b->iO06 || ((a->iO06 == b->iO06) && (a->iO00 < b->iO00));
	case FIELD_BAODAN_iO07:
		return a->iO07 < b->iO07 || ((a->iO07 == b->iO07) && (a->iO00 < b->iO00));
	}
}
// 报单排序比较大于条件判断
static bool _compare_baodan_gt(void* data1, void* data2, int field) {
	SBAODAN* a = (SBAODAN*)data1;
	SBAODAN* b = (SBAODAN*)data2;
	switch (field) {
	case FIELD_BAODAN_NONE:
	default:
		return a->iO00 > b->iO00;
	case FIELD_BAODAN_iT12_part:
		return a->iT12_part > b->iT12_part || ((a->iT12_part == b->iT12_part) && (a->iO00 > b->iO00));
	case FIELD_BAODAN_cI10:
		return a->cI10 > b->cI10 || ((a->cI10 == b->cI10) && (a->iO00 > b->iO00));
	case FIELD_BAODAN_iM30:
		return a->iM30 > b->iM30 || ((a->iM30 == b->iM30) && (a->iO00 > b->iO00));
	case FIELD_BAODAN_iO06:
		return a->iO06 > b->iO06 || ((a->iO06 == b->iO06) && (a->iO00 > b->iO00));
	case FIELD_BAODAN_iO07:
		return a->iO07 > b->iO07 || ((a->iO07 == b->iO07) && (a->iO00 > b->iO00));
	}
}
// 成交单排序比较小于条件判断
static bool _compare_chengjiaodan_lt(void* data1, void* data2, int field) {
	SCHENGJIAODAN* a = (SCHENGJIAODAN*)data1;
	SCHENGJIAODAN* b = (SCHENGJIAODAN*)data2;
	int v = memcmp(a->sO60, b->sO60, LENGTH_CJD);
	switch (field) {
	case FIELD_CHENGJIAODAN_NONE:
	default:
		return v < 0 || (v == 0 && a->cO02 < b->cO02);
	case FIELD_CHENGJIAODAN_iO62_part:
		return a->iO62_part < b->iO62_part || ((a->iO62_part == b->iO62_part) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	case FIELD_CHENGJIAODAN_cI10:
		return a->cI10 < b->cI10 || ((a->cI10 == b->cI10) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	case FIELD_CHENGJIAODAN_iM30:
		return a->iM30 < b->iM30 || ((a->iM30 == b->iM30) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	case FIELD_CHENGJIAODAN_iO63:
		return a->iO63 < b->iO63 || ((a->iO63 == b->iO63) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	case FIELD_CHENGJIAODAN_iO64:
		return a->iO64 < b->iO64 || ((a->iO64 == b->iO64) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	}
}
// 成交单排序比较大于条件判断
static bool _compare_chengjiaodan_gt(void* data1, void* data2, int field) {
	SCHENGJIAODAN* a = (SCHENGJIAODAN*)data1;
	SCHENGJIAODAN* b = (SCHENGJIAODAN*)data2;
	int v = memcmp(a->sO60, b->sO60, LENGTH_CJD);
	switch (field) {
	case FIELD_CHENGJIAODAN_NONE:
	default:
		return v > 0 || (v == 0 && a->cO02 > b->cO02);
	case FIELD_CHENGJIAODAN_iO62_part:
		return a->iO62_part > b->iO62_part || ((a->iO62_part == b->iO62_part) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	case FIELD_CHENGJIAODAN_cI10:
		return a->cI10 > b->cI10 || ((a->cI10 == b->cI10) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	case FIELD_CHENGJIAODAN_iM30:
		return a->iM30 > b->iM30 || ((a->iM30 == b->iM30) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	case FIELD_CHENGJIAODAN_iO63:
		return a->iO63 > b->iO63 || ((a->iO63 == b->iO63) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	case FIELD_CHENGJIAODAN_iO64:
		return a->iO64 > b->iO64 || ((a->iO64 == b->iO64) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	}
}
// 交割报单排序比较小于条件判断
static bool _compare_jiaoge_lt(void* data1, void* data2, int field) {
	SJIAOGE* a = (SJIAOGE*)data1;
	SJIAOGE* b = (SJIAOGE*)data2;
	switch (field) {
	case FIELD_JIAOGE_NONE:
	default:
		return a->iO00 < b->iO00;
	case FIELD_JIAOGE_iT12_part:
		return a->iT12_part < b->iT12_part || ((a->iT12_part == b->iT12_part) && (a->iO00 < b->iO00));
	case FIELD_JIAOGE_iM30:
		return a->iM30 < b->iM30 || ((a->iM30 == b->iM30) && (a->iO00 < b->iO00));
	case FIELD_JIAOGE_cI10:
		return a->cI10 < b->cI10 || ((a->cI10 == b->cI10) && (a->iO00 < b->iO00));
	case FIELD_JIAOGE_iO07:
		return a->iO07 < b->iO07 || ((a->iO07 == b->iO07) && (a->iO00 < b->iO00));
	}
}
// 交割报单排序比较大于条件判断
static bool _compare_jiaoge_gt(void* data1, void* data2, int field) {
	SJIAOGE* a = (SJIAOGE*)data1;
	SJIAOGE* b = (SJIAOGE*)data2;
	switch (field) {
	case FIELD_JIAOGE_NONE:
	default:
		return a->iO00 > b->iO00;
	case FIELD_JIAOGE_iT12_part:
		return a->iT12_part > b->iT12_part || ((a->iT12_part == b->iT12_part) && (a->iO00 > b->iO00));
	case FIELD_JIAOGE_iM30:
		return a->iM30 > b->iM30 || ((a->iM30 == b->iM30) && (a->iO00 > b->iO00));
	case FIELD_JIAOGE_cI10:
		return a->cI10 > b->cI10 || ((a->cI10 == b->cI10) && (a->iO00 > b->iO00));
	case FIELD_JIAOGE_iO07:
		return a->iO07 > b->iO07 || ((a->iO07 == b->iO07) && (a->iO00 > b->iO00));
	}
}
// 中立仓报单排序比较小于条件判断
static bool _compare_zhonglicang_lt(void* data1, void* data2, int field) {
	SZHONGLICANG* a = (SZHONGLICANG*)data1;
	SZHONGLICANG* b = (SZHONGLICANG*)data2;
	switch (field) {
	case FIELD_ZHONGLICANG_NONE:
	default:
		return a->iO00 < b->iO00;
	case FIELD_ZHONGLICANG_iT12_part:
		return a->iT12_part < b->iT12_part || ((a->iT12_part == b->iT12_part) && (a->iO00 < b->iO00));
	case FIELD_ZHONGLICANG_iM30:
		return a->iM30 < b->iM30 || ((a->iM30 == b->iM30) && (a->iO00 < b->iO00));
	case FIELD_ZHONGLICANG_cI10:
		return a->cI10 < b->cI10 || ((a->cI10 == b->cI10) && (a->iO00 < b->iO00));
	case FIELD_ZHONGLICANG_iO07:
		return a->iO07 < b->iO07 || ((a->iO07 == b->iO07) && (a->iO00 < b->iO00));
	}
}
// 中立仓报单排序比较大于条件判断
static bool _compare_zhonglicang_gt(void* data1, void* data2, int field) {
	SZHONGLICANG* a = (SZHONGLICANG*)data1;
	SZHONGLICANG* b = (SZHONGLICANG*)data2;
	switch (field) {
	case FIELD_ZHONGLICANG_NONE:
	default:
		return a->iO00 > b->iO00;
	case FIELD_ZHONGLICANG_iT12_part:
		return a->iT12_part > b->iT12_part || ((a->iT12_part == b->iT12_part) && (a->iO00 > b->iO00));
	case FIELD_ZHONGLICANG_iM30:
		return a->iM30 > b->iM30 || ((a->iM30 == b->iM30) && (a->iO00 > b->iO00));
	case FIELD_ZHONGLICANG_cI10:
		return a->cI10 > b->cI10 || ((a->cI10 == b->cI10) && (a->iO00 > b->iO00));
	case FIELD_ZHONGLICANG_iO07:
		return a->iO07 > b->iO07 || ((a->iO07 == b->iO07) && (a->iO00 > b->iO00));
	}
}
// 交割、中立仓成交单排序比较小于条件判断
static bool _compare_jg_zlc_chengjiaodan_lt(void* data1, void* data2, int field) {
	SJG_ZLC_CHENGJIAODAN* a = (SJG_ZLC_CHENGJIAODAN*)data1;
	SJG_ZLC_CHENGJIAODAN* b = (SJG_ZLC_CHENGJIAODAN*)data2;
	int v = memcmp(a->sO60, b->sO60, LENGTH_CJD);
	switch (field) {
	case FIELD_JG_ZLC_CHENGJIAODAN_NONE:
	default:
		return v < 0 || (v == 0 && a->cO02 < b->cO02);
	case FIELD_JG_ZLC_CHENGJIAODAN_iO62_part:
		return a->iO62_part < b->iO62_part || ((a->iO62_part == b->iO62_part) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	case FIELD_JG_ZLC_CHENGJIAODAN_cI10:
		return a->cI10 < b->cI10 || ((a->cI10 == b->cI10) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	case FIELD_JG_ZLC_CHENGJIAODAN_iM30:
		return a->iM30 < b->iM30 || ((a->iM30 == b->iM30) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	case FIELD_JG_ZLC_CHENGJIAODAN_iO64:
		return a->iO64 < b->iO64 || ((a->iO64 == b->iO64) && (v < 0 || (v == 0 && a->cO02 < b->cO02)));
	}
}
// 交割、中立仓成交单排序比较大于条件判断
static bool _compare_jg_zlc_chengjiaodan_gt(void* data1, void* data2, int field) {
	SJG_ZLC_CHENGJIAODAN* a = (SJG_ZLC_CHENGJIAODAN*)data1;
	SJG_ZLC_CHENGJIAODAN* b = (SJG_ZLC_CHENGJIAODAN*)data2;
	int v = memcmp(a->sO60, b->sO60, LENGTH_CJD);
	switch (field) {
	case FIELD_JG_ZLC_CHENGJIAODAN_NONE:
	default:
		return v > 0 || (v == 0 && a->cO02 > b->cO02);
	case FIELD_JG_ZLC_CHENGJIAODAN_iO62_part:
		return a->iO62_part > b->iO62_part || ((a->iO62_part == b->iO62_part) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	case FIELD_JG_ZLC_CHENGJIAODAN_cI10:
		return a->cI10 > b->cI10 || ((a->cI10 == b->cI10) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	case FIELD_JG_ZLC_CHENGJIAODAN_iM30:
		return a->iM30 > b->iM30 || ((a->iM30 == b->iM30) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	case FIELD_JG_ZLC_CHENGJIAODAN_iO64:
		return a->iO64 > b->iO64 || ((a->iO64 == b->iO64) && (v > 0 || (v == 0 && a->cO02 > b->cO02)));
	}
}
// 公告排序比较小于条件判断
static bool _compare_gonggao_lt(void* data1, void* data2, int field) {
	SGONGGAO* a = (SGONGGAO*)data1;
	SGONGGAO* b = (SGONGGAO*)data2;
	return a->iT80 < b->iT80;
}
// 公告排序比较大于条件判断
static bool _compare_gonggao_gt(void* data1, void* data2, int field) {
	SGONGGAO* a = (SGONGGAO*)data1;
	SGONGGAO* b = (SGONGGAO*)data2;
	return a->iT80 > b->iT80;
}

// 报单满足筛选条件判断
static bool _matchfilter_baodan(void* filter, void* data) {
	SFILTER_BAODAN* f = (SFILTER_BAODAN*)filter;
	SBAODAN* d = (SBAODAN*)data;
	if (f->cI10 != -1 && f->cI10 != d->cI10)
		return false;
	if (f->cO15 != -1 && f->cO15 != d->cO15)
		return false;
	if (f->cO09 != -1 && f->cO09 != d->cO09)
		return false;
	if (f->iM20 != -1 && f->iM20 != d->iM20)
		return false;
	if (f->iM30 != -1 && f->iM30 != d->iM30)
		return false;
	return true;
}
// 报单满足查询条件判断
static bool _matchquery_baodan(void* query, void* data) {
	SQUERY_BAODAN* q = (SQUERY_BAODAN*)query;
	SBAODAN* d = (SBAODAN*)data;
	if (q->cI10 != -1 && q->cI10 != d->cI10)
		return false;
	if (q->cI00 != -1 && q->cI00 != d->cI00)
		return false;
	if (q->cO02 != -1 && q->cO02 != d->cO02)
		return false;
	if (q->cO03 != -1 && q->cO03 != d->cO03)
		return false;
	if (q->iO00 != -1 && q->iO00 != d->iO00)
		return false;
	if (q->iM20 != -1 && q->iM20 != d->iM20)
		return false;
	if (q->iM30 != -1 && q->iM30 != d->iM30)
		return false;
	if (q->sM20_part != -1 && q->sM20_part != d->sM20_part)
		return false;
	return true;
}
// 交割报单满足筛选条件判断
static bool _matchfilter_jiaoge(void* filter, void* data) {
	SFILTER_JIAOGE* f = (SFILTER_JIAOGE*)filter;
	SJIAOGE* d = (SJIAOGE*)data;
	if (f->cI10 != -1 && f->cI10 != d->cI10)
		return false;
	if (f->cO15 != -1 && f->cO15 != d->cO15)
		return false;
	if (f->cO09 != -1 && f->cO09 != d->cO09)
		return false;
	if (f->iM20 != -1 && f->iM20 != d->iM20)
		return false;
	if (f->iM30 != -1 && f->iM30 != d->iM30)
		return false;
	return true;
}
// 交割报单满足查询条件判断
static bool _matchquery_jiaoge(void* query, void* data) {
	SQUERY_JIAOGE* q = (SQUERY_JIAOGE*)query;
	SJIAOGE* d = (SJIAOGE*)data;
	if (q->cI10 != -1 && q->cI10 != d->cI10)
		return false;
	if (q->cO02 != -1 && q->cO02 != d->cO02)
		return false;
	if (q->iO00 != -1 && q->iO00 != d->iO00)
		return false;
	if (q->iM20 != -1 && q->iM20 != d->iM20)
		return false;
	if (q->iM30 != -1 && q->iM30 != d->iM30)
		return false;
	if (q->sM20_part != -1 && q->sM20_part != d->sM20_part)
		return false;
	return true;
}
// 中立仓报单满足筛选条件判断
static bool _matchfilter_zhonglicang(void* filter, void* data) {
	SFILTER_ZHONGLICANG* f = (SFILTER_ZHONGLICANG*)filter;
	SZHONGLICANG* d = (SZHONGLICANG*)data;
	if (f->cI10 != -1 && f->cI10 != d->cI10)
		return false;
	if (f->cO15 != -1 && f->cO15 != d->cO15)
		return false;
	if (f->cO09 != -1 && f->cO09 != d->cO09)
		return false;
	if (f->iM20 != -1 && f->iM20 != d->iM20)
		return false;
	if (f->iM30 != -1 && f->iM30 != d->iM30)
		return false;
	return true;
}
// 中立仓报单满足查询条件判断
static bool _matchquery_zhonglicang(void* query, void* data) {
	SQUERY_ZHONGLICANG* q = (SQUERY_ZHONGLICANG*)query;
	SZHONGLICANG* d = (SZHONGLICANG*)data;
	if (q->cI10 != -1 && q->cI10 != d->cI10)
		return false;
	if (q->cO02 != -1 && q->cO02 != d->cO02)
		return false;
	if (q->cI10 != -1 && q->cI10 != d->cI10)
		return false;
	if (q->iO00 != -1 && q->iO00 != d->iO00)
		return false;
	if (q->iM20 != -1 && q->iM20 != d->iM20)
		return false;
	if (q->iM30 != -1 && q->iM30 != d->iM30)
		return false;
	if (q->sM20_part != -1 && q->sM20_part != d->sM20_part)
		return false;
	return true;
}
// 成交单满足筛选条件判断
static bool _matchfilter_chengjiaodan(void* filter, void* data) {
	SFILTER_CHENGJIAODAN* f = (SFILTER_CHENGJIAODAN*)filter;
	SCHENGJIAODAN* d = (SCHENGJIAODAN*)data;
	if (f->cI10 != -1 && f->cI10 != d->cI10)
		return false;
	if (f->iM20 != -1 && f->iM20 != d->iM20)
		return false;
	if (f->iM30 != -1 && f->iM30 != d->iM30)
		return false;
	return true;
}
// 成交单满足查询条件判断
static bool _matchquery_chengjiaodan(void* query, void* data) {
	SQUERY_CHENGJIAODAN* q = (SQUERY_CHENGJIAODAN*)query;
	SCHENGJIAODAN* d = (SCHENGJIAODAN*)data;
	if (q->cI10 != -1 && q->cI10 != d->cI10)
		return false;
	if (q->cI00 != -1 && q->cI00 != d->cI00)
		return false;
	if (q->cO02 != -1 && q->cO02 != d->cO02)
		return false;
	if (q->cO03 != -1 && q->cO03 != d->cO03)
		return false;
	if (q->sO60[0] != 0x00 && memcmp(q->sO60, d->sO60, LENGTH_CJD) != 0)
		return false;
	if (q->iO00 != -1 && q->iO00 != d->iO00)
		return false;
	if (q->iM20 != -1 && q->iM20 != d->iM20)
		return false;
	if (q->iM30 != -1 && q->iM30 != d->iM30)
		return false;
	if (q->sM20_part != -1 && q->sM20_part != d->sM20_part)
		return false;
	return true;
}
// 交割、中立仓成交单满足筛选条件判断
static bool _matchfilter_jg_zlc_chengjiaodan(void* filter, void* data) {
	SFILTER_JG_ZLC_CHENGJIAODAN* f = (SFILTER_JG_ZLC_CHENGJIAODAN*)filter;
	SJG_ZLC_CHENGJIAODAN* d = (SJG_ZLC_CHENGJIAODAN*)data;
	if (f->cO05 != -1 && f->cO05 != d->cO05)
		return false;
	if (f->cI10 != -1 && f->cI10 != d->cI10)
		return false;
	if (f->iM20 != -1 && f->iM20 != d->iM20)
		return false;
	if (f->iM30 != -1 && f->iM30 != d->iM30)
		return false;
	return true;
}
// 交割、中立仓成交单满足查询条件判断
static bool _matchquery_jg_zlc_chengjiaodan(void* query, void* data) {
	SQUERY_JG_ZLC_CHENGJIAODAN* q = (SQUERY_JG_ZLC_CHENGJIAODAN*)query;
	SJG_ZLC_CHENGJIAODAN* d = (SJG_ZLC_CHENGJIAODAN*)data;
	if (q->cI10 != -1 && q->cI10 != d->cI10)
		return false;
	if (q->cO02 != -1 && q->cO02 != d->cO02)
		return false;
	if (q->cO05 != -1 && q->cO05 != d->cO05)
		return false;
	if (q->sO60[0] != 0x00 && memcmp(q->sO60, d->sO60, LENGTH_CJD) != 0)
		return false;
	if (q->iO00 != -1 && q->iO00 != d->iO00)
		return false;
	if (q->iM20 != -1 && q->iM20 != d->iM20)
		return false;
	if (q->iM30 != -1 && q->iM30 != d->iM30)
		return false;
	if (q->sM20_part != -1 && q->sM20_part != d->sM20_part)
		return false;
	return true;
}
// 公告满足筛选条件判断
static bool _matchfilter_gonggao(void* filter, void* data) {
	// SFILTER_GONGGAO *f = (SFILTER_GONGGAO*) filter;
	// SGONGGAO *d = (SGONGGAO*) data;
	return true;
}
// 公告满足查询条件判断
static bool _matchquery_gonggao(void* query, void* data) {
	SQUERY_GONGGAO* q = (SQUERY_GONGGAO*)query;
	SGONGGAO* d = (SGONGGAO*)data;
	if (q->iT80 != -1 && q->iT80 != d->iT80)
		return false;
	return true;
}

bool inited = false;  
bool (*_compare_lt[INDEX_MAX]) (void*, void*, int);
bool (*_compare_gt[INDEX_MAX]) (void*, void*, int);

static bool __isOpInited() {
    return inited;
}
static void __initOp() {
	if (!inited) {
		_compare_lt[INDEX_BAODAN] = _compare_baodan_lt;
		_compare_gt[INDEX_BAODAN] = _compare_baodan_gt;
		_compare_lt[INDEX_JIAOGE] = _compare_jiaoge_lt;
		_compare_gt[INDEX_JIAOGE] = _compare_jiaoge_gt;
		_compare_lt[INDEX_ZHONGLICANG] = _compare_zhonglicang_lt;
		_compare_gt[INDEX_ZHONGLICANG] = _compare_zhonglicang_gt;
		_compare_lt[INDEX_CHENGJIAODAN] = _compare_chengjiaodan_lt;
		_compare_gt[INDEX_CHENGJIAODAN] = _compare_chengjiaodan_gt;
		_compare_lt[INDEX_JG_CHENGJIAODAN] = _compare_jg_zlc_chengjiaodan_lt;
		_compare_gt[INDEX_JG_CHENGJIAODAN] = _compare_jg_zlc_chengjiaodan_gt;
		_compare_lt[INDEX_ZLC_CHENGJIAODAN] = _compare_jg_zlc_chengjiaodan_lt;
		_compare_gt[INDEX_ZLC_CHENGJIAODAN] = _compare_jg_zlc_chengjiaodan_gt;
		_compare_lt[INDEX_GONGGAO] = _compare_gonggao_lt;
		_compare_gt[INDEX_GONGGAO] = _compare_gonggao_gt;
	}
	inited = true;
}



#endif   /* COMPARATOR_CPP_H */
